"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RoomVideoDao = void 0;
const DbConfig_1 = require("../../src/config/DbConfig");
const DaoBase_1 = require("../../src/engine/dao/DaoBase");
const DateUtil_1 = require("../../src/engine/utils/DateUtil");
const Logger_1 = require("../../src/engine/utils/Logger");
const MysqlManager_1 = require("../../src/engine/utils/MysqlManager");
class RoomVideoDao extends DaoBase_1.DaoBase {
    static insertVideo(model) {
        return __awaiter(this, void 0, void 0, function* () {
            if (!model.isSave) {
                model.isSave = true;
                let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.DB_NAME);
                let sql = "insert into t_room_video (gameResultId, ju, time, videoResult, playerList, begin_gameInfo, actionList) VALUES(?,?,?,?,?,?,?) ;";
                let sqlParams = [model.gameResultId, model.ju, DateUtil_1.default.formatDateStr(model.time),
                    JSON.stringify(model.videoResult), JSON.stringify(model.playerList), JSON.stringify(model.begin_gameInfo),
                    JSON.stringify(model.actionList)];
                let rows = yield client.queryPromise(sql, sqlParams);
                // Logger.log("insertVideo====", rows)
                if (rows && rows["affectedRows"] > 0) {
                    return true;
                }
                else {
                    return false;
                }
            }
        });
    }
    static checkClear(delete_time) {
        return __awaiter(this, void 0, void 0, function* () {
            let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.DB_NAME);
            let sql = "delete from t_room_video where time < ?";
            let sqlParams = [DateUtil_1.default.formatDateStr(delete_time)];
            yield client.queryPromise(sql, sqlParams);
        });
    }
    static getByGameResultId(gameResultId) {
        return __awaiter(this, void 0, void 0, function* () {
            let sql = "select * from  t_room_video where `gameResultId`=?";
            let sqlParams = [gameResultId];
            let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.DB_NAME);
            let rows = yield client.queryPromise(sql, sqlParams);
            Logger_1.Logger.log("getByGameResultId", sql, sqlParams, rows);
            if (rows && rows.length > 0) {
                return rows;
            }
            return [];
        });
    }
}
exports.RoomVideoDao = RoomVideoDao;
RoomVideoDao.DB_NAME = DbConfig_1.DbConfig.Db_Name.db_admin;
RoomVideoDao.Tb_Name = "t_room_video";
